package es.agroservicio.Agroservicio.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import es.agroservicio.Agroservicio.domain.Product;
import es.agroservicio.Agroservicio.repository.ProductDAO;

@Component
public class ProductsManagerImpl implements ProductsManager {

	private static final long serialVersionUID = 1L;

	@Autowired
	private ProductDAO productDao;

	public void setProductDao(ProductDAO productDao) {
		this.productDao = productDao;
	}

	public List<Product> getProducts() {

		return productDao.findAllOrderedByName();
	}

	public Product getProductById(String id) {
		return productDao.findById(id);

	}

	public Map<String, String> getProductsIdName() {
		Map<String, String> mapProducts = new HashMap<String, String>();
		
		List<Product> products = productDao.findAllOrderedByName();

		for (Product pro : products)
			mapProducts.put(Integer.toString(pro.getIdProduct()), pro.getName());

		return mapProducts;
	}


}